NAME := ota

$(NAME)_MBINS_TYPE := kernel
$(NAME)_VERSION := 1.0.1
$(NAME)_SUMMARY := An over-the-air update is the wireless delivery of new software. 

#default gcc
ifeq ($(COMPILER),)
$(NAME)_CFLAGS      += -Wall -Werror
else ifeq ($(COMPILER),gcc)
$(NAME)_CFLAGS      += -Wall -Werror
endif

$(NAME)_INCLUDES += include hal ota_core/verify ota_core/mcu

ifneq (,$(filter breeze,$(COMPONENTS)))
GLOBAL_DEFINES += OTA_CONFIG_BLE
$(NAME)_COMPONENTS += breeze
$(NAME)_SOURCES := ota_core/download/ota_download_ble.c   \
                   ota_core/transport/ota_transport_ble.c

else ifneq (,$(filter libiot_mqtt,$(COMPONENTS)))
$(NAME)_SOURCES := ota_core/download/ota_download_http.c   \
                   ota_core/transport/ota_transport_mqtt.c

$(NAME)_COMPONENTS += libiot_mqtt http
else ifneq (,$(filter libiot_coap,$(COMPONENTS)))
$(NAME)_SOURCES := ota_core/download/ota_download_coap.c   \
                   ota_core/transport/ota_transport_coap.c

$(NAME)_COMPONENTS += libiot_coap
endif

$(NAME)_SOURCES += ota_core/ota_service.c \
                   ota_core/verify/ota_verify_hash.c \
                   ota_core/verify/ota_verify_rsa.c  \
                   hal/ota_hal_os.c                  \
                   hal/ota_hal_plat.c                \
                   hal/ota_hal_ctrl.c                \
                   hal/ota_hal_trans.c               \
                   hal/ota_hal_digest.c              \
                   hal/ota_hal_param.c               \
                   ota_core/mcu/ota_mcu_upgrade.c    \
                   ota_core/mcu/ota_mcu_ymodem.c     \
                   ota_core/mcu/ota_mcu_can.c        \
                   ota_core/mcu/ota_mcu_can_slave.c  \

$(NAME)_COMPONENTS += cjson

ifeq ($(USE_ITLS),y)
   $(NAME)_COMPONENTS += itls
   ifeq ($(COMPILER),armcc)
   GLOBAL_CFLAGS += -DOTA_CONFIG_ITLS -DCONFIG_HTTP_SECURE_ITLS=1 -DOTA_SIGNAL_CHANNEL=1 -DCONFIG_HTTP_SECURE=1
   else
   GLOBAL_DEFINES += OTA_CONFIG_ITLS CONFIG_HTTP_SECURE_ITLS=1 OTA_SIGNAL_CHANNEL=1 CONFIG_HTTP_SECURE=1
   endif
else
   $(NAME)_COMPONENTS += mbedtls
   ifeq ($(COMPILER),armcc)
       ifeq ($(HTTPS_DL),1)
       GLOBAL_CFLAGS += -DOTA_CONFIG_SECURE_DL_MODE -DMBEDTLS_CONFIG_TLS_MAX_CONTENT_LEN=8192
       endif
       ifneq (,$(filter mcu_esp8266,$(HOST_MCU_FAMILY)))
       GLOBAL_CFLAGS += -DOTA_SIGNAL_CHANNEL=1 -DCONFIG_HTTP_SECURE=1 -DOTA_CONFIG_SECURE_DL_MODE
       else
       GLOBAL_CFLAGS += -DOTA_SIGNAL_CHANNEL=1 -DCONFIG_HTTP_SECURE=1
       endif
   else
       ifeq ($(HTTPS_DL),1)
       GLOBAL_DEFINES += OTA_CONFIG_SECURE_DL_MODE MBEDTLS_CONFIG_TLS_MAX_CONTENT_LEN=8192
       endif
       ifneq (,$(filter mcu_esp8266,$(HOST_MCU_FAMILY)))
       GLOBAL_DEFINES += OTA_SIGNAL_CHANNEL=1 CONFIG_HTTP_SECURE=1 OTA_CONFIG_SECURE_DL_MODE
       else
       GLOBAL_DEFINES += OTA_SIGNAL_CHANNEL=1 CONFIG_HTTP_SECURE=1
       endif
   endif
endif
